package com.oracle.sbdb.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.oracle.sbdb.model.BugInfo;

public class BugInfoDao {
	public BugInfo selectbyId(int bugId){
		SqlSession session = SessionFactory.getSession();
		BugInfo res = session.selectOne("com.oracle.mybatis.BugInfoMapper.selectBugInfobyBugId", bugId);
		session.commit();
		session.close();
		return res;
	}
	
	public List<BugInfo> selectbyEmployeeId(int employeeId) {
		SqlSession session = SessionFactory.getSession();
		List<BugInfo> res = session.selectList("com.oracle.mybatis.BugInfoMapper.selectBugInfobyEmployeeId", employeeId);
		session.commit();
		session.close();
		return res;
	}
	
	public List<BugInfo> selectAllBugInfo() {
		SqlSession session = SessionFactory.getSession();
		List<BugInfo> res = session.selectList("com.oracle.mybatis.BugInfoMapper.selectAllBugInfo");
		session.commit();
		session.close();
		return res;
	}
	
	public List<BugInfo> selectbyKeyPhrase(String keyPhrase) {
		SqlSession session = SessionFactory.getSession();
		List<BugInfo> res = session.selectList("com.oracle.mybatis.BugInfoMapper.selectBugInfobyKeyPhrase", keyPhrase);
		session.commit();
		session.close();
		return res;
	}
	
	public List<BugInfo> selectbyComponentId(int componentId) {
		SqlSession session = SessionFactory.getSession();
		List<BugInfo> res = session.selectList("com.oracle.mybatis.BugInfoMapper.selectBugInfobyComponentId", componentId);
		session.commit();
		session.close();
		return res;
	}
	
	public int selectCount() {
		SqlSession session = SessionFactory.getSession();
		int res = session.selectOne("com.oracle.mybatis.BugInfoMapper.selectBugInfoCount");
		session.commit();
		session.close();
		return res;
	}
	
	public void insert(BugInfo bugInfo) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.BugInfoMapper.insertBugInfo", bugInfo);
		session.commit();
		session.close();
	}
	
	public void update(BugInfo bugInfo) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.BugInfoMapper.updateBugInfo", bugInfo);
		session.commit();
		session.close();
	}
	
	public void delete(int bugId) {
		SqlSession session = SessionFactory.getSession();
		session.selectOne("com.oracle.mybatis.BugInfoMapper.deleteBugInfo", bugId);
		session.commit();
		session.close();
	}
}
